package com.ysxsoft.wdg.wxapi;

import android.content.Intent;

import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.ysxsoft.wdg.MyApplication;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.base.BaseActivity;
import com.ysxsoft.wdg.pay.PayListenerUtils;


public class WXPayEntryActivity extends BaseActivity implements IWXAPIEventHandler {
    private IWXAPI api;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_wxpayentry;
    }

    @Override
    protected void initData() {
        api = WXAPIFactory.createWXAPI(this, MyApplication.WXAppId);
        api.handleIntent(getIntent(), this);
    }


    @Override
    protected void setListener() {

    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp baseResp) {
        if (baseResp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            switch (baseResp.errCode) {
                case 0://成功
                    PayListenerUtils.getInstance(this).addSuccess();
                    break;
                case -1://失败
                    PayListenerUtils.getInstance(this).addError();
                    break;
                case -2://取消
                    PayListenerUtils.getInstance(this).addCancel();
                    break;
            }
        }
        finish();
    }
}
